package com.example.demo.widget.chart.utils

import com.example.demo.widget.chart.ChartData
import com.example.demo.widget.chart.ChartItem

object ChartDataUtils {
    fun receiveItemAngleInfo(data: ChartData?,startAngle: Float,totalAngle: Float){
        val list = data?.itemList
        val total = data?.getItemValueTotal() ?: 0f
        if(list == null || list.isEmpty() || total <= 0){
            return
        }

        val listSize = list.size
        var currentAngle = startAngle
        for(index in 0 until listSize){
            val item = list[index]
            val sweepAngle = (item.value / total) * totalAngle

            item.startAngle = currentAngle
            item.swipeAngle = sweepAngle

            currentAngle += sweepAngle
        }
    }
}